/**
 * Created by LeungZ on 2016/10/16.
 */
import './detail/detail.scss';
import dtlTemp from './detail/detail.html';
import dtlCtrl from './detail/detail.ctrl.js';

import './detail/console/console.scss';
import cosTemp from './detail/console/console.html';
import cosCtrl from './detail/console/console.ctrl.js';

export default angular.module('ctg-k8sconsole').config(['$stateProvider', $stateProvider=> {
    $stateProvider.state('k8s-pod-detail', {
        url: '/k8s/:from/pod/:name?namesp&kDbCode&nodeIp&srvName',
        templateUrl: dtlTemp,
        controller: dtlCtrl,
        controllerAs: 'dtl',
        resolve: {
            detail: ['podSrv', 'ctgNotification', '$stateParams', function (podSrv, ctgNotification, $stateParams) {
                return podSrv.getDetail({
                    name: $stateParams.name,
                    namesp: $stateParams.namesp,
                    code: $stateParams.kDbCode
                }).catch(function () {
                    ctgNotification.error('获取容器详情数据有误.');
                });
            }],
            resource: ['podSrv', 'ctgNotification', '$stateParams', function (podSrv, ctgNotification, $stateParams) {
                return podSrv.getResource({
                    names: $stateParams.namesp + ':' + $stateParams.name,
                    code: $stateParams.kDbCode, isSingle: true
                }).catch(function (data) {
                    ctgNotification.error('获取宿主机资源数据有误.');
                });
            }]
        }
    }).state('k8s-pod-console', {
        url: '/k8s/:from/pod/:name/console?namesp&kDbCode&nodeIp&srvName',
        templateUrl: cosTemp,
        controller: cosCtrl,
        controllerAs: 'vm',
        resolve: {
            connection: ['podSrv', 'ctgNotification', function (podSrv, ctgNotification) {
                return podSrv.createConn().catch(function () {
                    ctgNotification.error('连接有误.');
                });
            }]
        }
    })
}]);